package com.lej.core.widget.customview

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import com.lej.core.R

class StrokeTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
    AppCompatTextView(context, attrs, defStyleAttr) {
    private var mStrokeColor = Color.WHITE
    private var mStrokeWidth = 0f
    override fun onDraw(canvas: Canvas) {
        paint.style = Paint.Style.FILL
        lTextColor?.let {
            setTextColor(it)
            super.onDraw(canvas)
        }

        // 只有描边
        paint.style = Paint.Style.STROKE
        paint.strokeWidth = mStrokeWidth
        setTextColor(mStrokeColor)
        super.onDraw(canvas)

    }

    var lTextColor: Int? = null

    init {
        if (attrs != null) {
            val a = context.obtainStyledAttributes(attrs, R.styleable.StrokeTextView)
            mStrokeColor = a.getColor(R.styleable.StrokeTextView_strokeColor, Color.WHITE)
            mStrokeWidth = a.getDimension(R.styleable.StrokeTextView_strokeWidth, 0f)
            a.recycle()
        }
        lTextColor = textColors.defaultColor
    }
}